/*   
 * QTextSetting.cpp
 *
 *  Created on: 2009-8-31
 *      Author: rockling
 */

#include "QTextSetting.h"
#include "QStoreFile.h"
#include "QFont.h"
#include "QFontManager.h"

#include "cx_typedef.h"
#include "cx_socket.h"


const QINT32 DEFAULTFONTHEIGHT = 18;
const QINT32 DEFAULTSPACE = 50;

CQTextSetting::CQTextSetting():
iVerticalSpace(2),
iFirstTip(QTRUE),
iColorType(CQTextSetting::USERCOLOR),
iFontHeight(16),
iBgColor(0),
iFontColor(0x000000),
iReadPosition(CQTextSetting::EREADNONE),
iLightIntensity(40),
iIsLightMode(QFALSE),
iIsKeyLight(QTRUE),
iSkinID(0),
iCurSortFlag(5),
iAPNID(-1),
iShortcutsStyleId(0),
iDownloadInform(QTRUE),
update(QFALSE),
iUpdateSequence(0),
Upgrade_time(0),
iFileSearchIndex(0),
iIsLightAllTime(QFALSE),
iIsLigthControl(QFALSE),
iIsBookCityShowPic(QTRUE),
iFontGlyph(QTRUE),
iReserveLine(QTRUE),
iCheckVersion(1),
iIsFromBookShelf(QFALSE),
iFocusOnTab(QTRUE),
iDefaultBG1(0),
iDefaultBG2(2),
iDefaultBG3(5),
iNextChapterState(NEXT_CHAPTER_NONE)
	{
	// TODO Auto-generated constructor stub

	}

CQTextSetting::~CQTextSetting()
{
	// TODO Auto-generated destructor stub
}

QVOID CQTextSetting::Init()
	{
	
	if(!InitSetting())
	{
		SetVerticalSpaceRelative( DEFAULTSPACE );
	}
	else 
	{
	}

	//if(Upgrade_time. == 0)
	if(1)
	{
//		TTime time;
//		time.HomeTime();
//		Upgrade_time = time.Int64();
		QTime dt; 
		cx_getLocalTime(&dt);
		Upgrade_time.SetDateTime(&dt);
	}
//sanford tmp 100521
	
#ifdef PLATFORM_SYMBIAN
	if(iAPNID <= 0)
	{
#ifdef __WINS__
	CArrayPtrFlat<CCIap> *pIapArray = new CArrayPtrFlat<CCIap>(8); 
	CArrayPtrFlat<CCIap>& iIapArray = *pIapArray;
	cx_iap_GetIapList(&iIapArray);
	iAPNID = iIapArray.At(0)->iIapId;
	pIapArray->ResetAndDestroy();
	delete pIapArray;
#else	
		iAPNID = cx_iap_GetCMWapId();				
#endif	
	}		
		
//			#ifdef __WINS__	
//				iAPNID = 3;
//			#endif	
				
#endif
}
	
QVOID CQTextSetting::SetTxtFont(QINT32 fontHeight)
{
	iFontHeight = fontHeight;
}

QVOID CQTextSetting::SetTxtFont(QINT32 fontHeight,QINT aGlyphBitmap)
{
	iFontHeight = fontHeight;
}

QINT32 CQTextSetting::GetFontHeight()
{
	return 0;
}

QINT32 CQTextSetting::GetVerticalSpace()
	{
	return iVerticalSpace;
	}

QVOID CQTextSetting::SetVerticalSpace(QINT32 aSpace)
	{
	iVerticalSpace = aSpace;
	}

QVOID CQTextSetting::SetVerticalSpaceRelative(QINT32 aRatio)
	{
	iVerticalSpace =( GetFontHeight()* aRatio ) /100;
	}

QINT32 CQTextSetting::GetVerticalSpaceRelative()
	{
	return (iVerticalSpace*100)/GetFontHeight();
	}

QVOID CQTextSetting::SetFileManPath(CQWString& aFileManPath)
{
	iFileManPath.Empty();
	iFileManPath = aFileManPath;
}

QVOID CQTextSetting::SetUserID(CQWString& UserID)
{
	iUserID.Empty();
	iUserID = UserID;
}

QVOID CQTextSetting::SetLastHomePageDate(CQWString& date)
{
	iLastHomePageDate.Empty();
	iLastHomePageDate = date;
}

QVOID CQTextSetting::SetFileSearchIndex(QINT32 aFileSearchIndex)
{
	if(aFileSearchIndex < 0)
		return;
	iFileSearchIndex = aFileSearchIndex;
}

TQProgressBarColor* CQTextSetting::GetProgressBarColor(QINT aIndex)
{
	if(aIndex<0 || aIndex >= iProgressBarColorArray.Count())
		return NULL;
	
	return iProgressBarColorArray.GetAt(aIndex);
}

TQAutoScorllBarColor* CQTextSetting::GetAutoScorllBarColor(QINT aIndex)
{
	if(aIndex<0 || aIndex >= iAutoScorllBarColorArray.Count())
		return NULL;
		
	return iAutoScorllBarColorArray.GetAt(aIndex);
}

TQAutoScorllLineColor* CQTextSetting::GetAutoScorllLineColor(QINT aIndex)
{
	if(aIndex<0 || aIndex >= iAutoScorllLineColorArray.Count())
		return NULL;
			
	return iAutoScorllLineColorArray.GetAt(aIndex);
}

QVOID CQTextSetting::SaveSetting()
{
	ReaderSetting setting;
	setting.colorId = this->iColorType;
	setting.fontHeight = this->iFontHeight;
	setting.verticalSpace = this->iVerticalSpace;
	setting.lastReadPath = this->iLastReadPath;
	setting.fileManPath = this->iFileManPath;
	setting.iFirstTip = this->iFirstTip;
	setting.fontColor = this->iFontColor;
	setting.bgColor = this->iBgColor;
	setting.readPosition = this->iReadPosition;
	setting.lightIntensity = this->iLightIntensity;
	setting.isLightMode = this->iIsLightMode;
    setting.isLightAllTime = this->iIsLightAllTime;
	setting.isLigthControl = this->iIsLigthControl;
	setting.isBookCityShowPic = this->iIsBookCityShowPic;
	setting.curSortFlag = this->iCurSortFlag;
	setting.apnID = this->iAPNID;
	setting.downloadInform = this->iDownloadInform;
	setting.update_time = this->Upgrade_time;
	setting.update = this->update;
	setting.fileSearchIndex = this->iFileSearchIndex;
	setting.updateSequence = this->iUpdateSequence;
	setting.userid = this->iUserID;
	setting.fontGlyph = this->iFontGlyph;
	setting.reserveLine = this->iReserveLine;
	setting.scrollType = this->iScrollType;
	setting.scrollSpeed = this->iScrollSpeed;
	setting.iLastHomePageDate = this->iLastHomePageDate;
	setting.shortcutsStyleId = this->iShortcutsStyleId;
	setting.skinID = this->iSkinID;
	setting.defaultBG1 = this->iDefaultBG1;
	setting.defaultBG2 = this->iDefaultBG2;
	setting.defaultBG3 = this->iDefaultBG3;
	setting.isKeyLight = this->iIsKeyLight;
	CQStoreFile file;
	file.PutReaderSetting(setting);
}

QBOOL CQTextSetting::InitSetting()
{
	ReaderSetting setting;
	CQStoreFile file;
	if(file.GetReaderSetting(setting) <0)
	{
		return QFALSE;
	}

	this->iColorType = setting.colorId;
	this->iFontHeight = setting.fontHeight;
	this->iVerticalSpace = setting.verticalSpace;
	this->iLastReadPath = setting.lastReadPath;
	this->iFileManPath = setting.fileManPath;
	this->iFirstTip = setting.iFirstTip;
	this->iFontColor = setting.fontColor;
	this->iBgColor = setting.bgColor;
	this->iReadPosition = setting.readPosition;
	this->iLightIntensity = setting.lightIntensity;
	this->iIsLightMode = setting.isLightMode;
    this->iIsLightAllTime = setting.isLightAllTime;
	this->iIsLigthControl = setting.isLigthControl;
	this->iIsBookCityShowPic = setting.isBookCityShowPic;
	this->iCurSortFlag = setting.curSortFlag;
	this->iAPNID = setting.apnID;
	this->iShortcutsStyleId = setting.shortcutsStyleId;
	this->iDownloadInform = setting.downloadInform;
	this->Upgrade_time = setting.update_time;
	this->update = setting.update;
	this->iFileSearchIndex = setting.fileSearchIndex;
	this->iUpdateSequence = setting.updateSequence;
	this->iUserID = setting.userid;
	this->iFontGlyph = setting.fontGlyph;
	this->iReserveLine = setting.reserveLine;
	this->iScrollType = setting.scrollType;
	this->iScrollSpeed = setting.scrollSpeed;
	this->iLastHomePageDate = setting.iLastHomePageDate;
	this->iDefaultBG1 = setting.defaultBG1;
	this->iDefaultBG2 = setting.defaultBG2;
	this->iDefaultBG3 = setting.defaultBG3;
	this->iSkinID = setting.skinID;
	this->iIsKeyLight = setting.isKeyLight;
	return QTRUE;
}
